﻿Imports System.Runtime.InteropServices

''' <summary>
''' IndexingComponentRegister
''' </summary>
Public NotInheritable Class IndexingComponentRegister


#Region "Register"

    ''' <summary>
    ''' RegisterIndexingComponent
    ''' </summary>
    ''' <param name="id">The component's GUID or ProgID. </param>
    ''' <param name="title">Component title that will be displayed on the GD preferences page. </param>
    ''' <param name="description">Component description that will be displayed on the GD preferences page. </param>
    ''' <param name="icon">A string pointing to an ICON resource, of the form "c:\program files\boo\comp.dll,23". This icon may be used to indicate the component and its results on various GD pages. </param>
    ''' <param name="extension"> An extension on which this component wishes to receive notifications from the crawler. If no interest in handling extensions the parameter must be NULL.</param>
    Public Shared Sub Register(ByVal id As String, ByVal title As String, ByVal description As String, ByVal icon As String, ByVal extension As String)

        Try
            Dim gdsReg As New GoogleDesktopIndexingComponentRegister


            Dim componentdesc = New Object(5) {"Title", title, "Description", description, "Icon", icon}

            Dim gdsic = gdsReg.RegisterIndexingComponent(id, componentdesc)


            If Not String.IsNullOrEmpty(extension) Then


                gdsic.RegisterExtension(extension)

                My.Application.Log.WriteEntry(String.Format("Registration extension '{0}' Successfully!", extension), TraceEventType.Information)
            End If

            My.Application.Log.WriteEntry(String.Format("Registration Component {0} {1}  Successfully!", id, title), TraceEventType.Information)

        Catch ex As Exception When LogException(ex)
        Catch ex As COMException
            GDException(ex)
        Catch ex As Exception
            Throw
        End Try

    End Sub

    ''' <summary>
    ''' RegisterIndexingComponent
    ''' </summary>
    ''' <param name="type">The component's Class. </param>
    ''' <param name="title">Component title that will be displayed on the GD preferences page. </param>
    ''' <param name="description">Component description that will be displayed on the GD preferences page. </param>
    ''' <param name="icon">A string pointing to an ICON resource, of the form "c:\program files\boo\comp.dll,23". This icon may be used to indicate the component and its results on various GD pages. </param>
    ''' <param name="extension"> An extension on which this component wishes to receive notifications from the crawler. If no interest in handling extensions the parameter must be NULL.</param>
    Public Shared Sub Register(ByVal type As Type, ByVal title As String, ByVal description As String, ByVal icon As String, ByVal extension As String)
        Dim id As String = GetComponentGUID(type)
        Register(id, title, description, icon, extension)
    End Sub
    ''' <summary>
    ''' RegisterIndexingComponent
    ''' </summary>
    ''' <param name="type">The component's Class. </param>
    ''' <param name="title">Component title that will be displayed on the GD preferences page. </param>
    ''' <param name="description">Component description that will be displayed on the GD preferences page. </param>
    ''' <param name="icon">A string pointing to an ICON resource, of the form "c:\program files\boo\comp.dll,23". This icon may be used to indicate the component and its results on various GD pages. </param>
    Public Shared Sub Register(ByVal type As Type, ByVal title As String, ByVal description As String, ByVal icon As String)
        Dim lExtension As String = String.Empty
        Register(type, title, description, icon, lExtension)
    End Sub
    ''' <summary>
    ''' RegisterIndexingComponent
    ''' </summary>
    ''' <param name="id">The component's GUID or ProgID. </param>
    ''' <param name="title">Component title that will be displayed on the GD preferences page. </param>
    ''' <param name="description">Component description that will be displayed on the GD preferences page. </param>
    ''' <param name="icon">A string pointing to an ICON resource, of the form "c:\program files\boo\comp.dll,23". This icon may be used to indicate the component and its results on various GD pages. </param>
    Public Shared Sub Register(ByVal id As String, ByVal title As String, ByVal description As String, ByVal icon As String)
        Dim lExtension As String = String.Empty
        Register(id, title, description, icon, lExtension)
    End Sub

#End Region





#Region "Unregister"
    ''' <summary>
    ''' UnregisterIndexingComponent
    ''' </summary>
    ''' <param name="id">The component's GUID or ProgID.</param>
    Public Shared Sub Unregister(ByVal id As String)
        Try
            Dim gdsreg As New GoogleDesktopIndexingComponentRegister

            gdsreg.UnregisterIndexingComponent(id)

            My.Application.Log.WriteEntry(String.Format("Component {0} Unregistered  Successfully!", id), TraceEventType.Information)
        Catch ex As Exception When LogException(ex)
        Catch ex As COMException
            GDException(ex)
        Catch ex As Exception
            Throw
        End Try
    End Sub
    ''' <summary>
    ''' UnregisterIndexingComponent
    ''' </summary>
    ''' <param name="type">The component's class</param>
    Public Shared Sub Unregister(ByVal type As System.Type)
        Dim lId As String = GetComponentGUID(type)
        Unregister(lId)
    End Sub
#End Region



  
End Class
